<?php

/*
*******
*******
**********商品图片上传************
*******
*******
*/
class GoodspicAction extends Action
{
	public function preMethod()
	{
		R("Mayijie/check_admin");
		$perm_key = session('admin_perm');
		$perm_arr = explode(",",$perm_key);
		if(!in_array(4,$perm_arr)){
			$this->error("无权操作");
		}
	}

	public function index(){
		$this->display();
	}

	public function upload() {
		//@@@生成日期保存目录
		$path=date("Ymd");
		foreach($_FILES as $k=>$v){
			if (!empty($v['name'])) {
				return $pic=$this->pic_up($path);
			}
		}
    }

	//@@@普通橱窗图片上传
    public function pic_up($path) {
        import('ORG.Net.UploadFile');
        $upload = new UploadFile();
        $upload->maxSize            = 3292200;
        $upload->allowExts          = explode(',', 'jpg,gif,png,jpeg'); 
		$upload->savePath           = './uploads/'.$path.'/';
        $upload->thumb              = true;
        $upload->imageClassPath     = 'ORG.Util.Image';
        $upload->thumbPrefix        = 's_,m_,b_';  //生产1张缩略图
        $upload->thumbMaxWidth      = '68,350,800';
        $upload->thumbMaxHeight     = '68,350,800';
        $upload->saveRule           = 'uniqid';
        $upload->thumbRemoveOrigin  = true;
		
        if (!$upload->upload()) {
            $this->error($upload->getErrorMsg());
        } else {
            return $upload->getUploadFileInfo();
        }
    }
	//upload -end

	//接收图片
	public function get_pic(){
		$pid=$this->_get('pic_id');
		$nn=$this->del_pic($pid);
		echo $nn;
	}

	//图片删除
	public function del_pic($pid){
		$Pic=M('Goods_pic');
		$map['pic_id']=$pid;
		$pic=$Pic->where($map)->find();

		if(unlink($pic['s_pic'])&&unlink($pic['m_pic'])&&unlink($pic['b_pic'])){
		    $result=$Pic->where($map)->delete();
			if($result){echo '1';}
		}else{
			echo '0';
		}
	}

}




/*
  [key] => pic
            [name] => 1.jpg
            [type] => image/pjpeg
            [size] => 34838
            [extension] => jpg
            [savepath] => ./uploads/small/
            [savename] => 518119b46d7f4.jpg
            [hash] => 
*/
?>